package com.edie.customview.data.net;

import com.edie.customview.data.net.entity.HttpResponse;
import com.edie.customview.data.net.exception.ApiException;

import io.reactivex.functions.Function;

/**
 * edie create on 2018/8/15
 */
public class HttpFunction<T> implements Function<HttpResponse<T>, T> {
    @Override
    public T apply(HttpResponse<T> tHttpResponse) throws Exception {
        if (tHttpResponse.code == 1) {
            return tHttpResponse.data;
        } else {
            throw new ApiException(tHttpResponse.code, tHttpResponse.msg);
        }
    }
}
